package ynu.elm.Dao;

import tools.utils;
import ynu.elm.entities.Menu;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class MenuDao extends Menu {
    public void showMenu(String identity){
        try {
            getUser().getResource().setCon(utils.getConnection());
            String sql="SELECT * FROM `menu` WHERE `identity` =?";
            PreparedStatement prepareStatement = getUser().getResource().getCon().prepareStatement(sql);
            prepareStatement.setString(1,identity);
            getUser().getResource().setRs(prepareStatement.executeQuery());
            PrintMenu(getUser().getResource().getRs());
        } catch (SQLException e) {
            e.printStackTrace();}
        finally {
            utils.release(getUser().getResource().getRs(), getUser().getResource().getSt(), getUser().getResource().getCon());
        }
    }
    public void PrintMenu(ResultSet rs) throws SQLException {
        int i=0;
        System.out.print("========== ");
        while(rs.next()){
            System.out.print("="+(++i)+""+rs.getObject("function")+"=");
        }
        System.out.println(" ==========");
    }
}
